<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>团队修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="clazzname" class="layui-form-label">
                <span class="x-red">*</span>团队名
            </label>
            <div class="layui-input-inline">
                <label type="text" id="clazzname"   class="layui-form-label"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="per" class="layui-form-label">
                <span class="x-red">*</span>带队人员
            </label>
            <div class="layui-col-md6 layui-input-inline">
                <select name="perid" id="per">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="start" class="layui-form-label">
                <span class="x-red">*</span>团队组建时间
            </label>
            <div class="layui-input-inline">
                <label class="layui-form-label" placeholder="团队组建时间"  id="start" readonly="readonly"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">竞赛方向</label>
            <div class="layui-input-block">
                <label class="layui-form-label" placeholder="竞赛方向"  id="major" readonly="readonly"/>
            </div>
        </div>
        <div class="layui-form-item" >
            <label for="realName" class="layui-form-label">新增成员</label>
            <div class="layui-input-inline" style="width: 80%">
                <input type="text" id="realName" autocomplete="off" class="layui-input" placeholder="成员姓名" style="display: inline-block;width: 20%">
                <input type="text" id="phone" autocomplete="off" class="layui-input" placeholder="成员电话" style="display: inline-block;width: 20%">
                <div class="layui-input-inline" style="display: inline-block;width: 20%">
                    <select id="checkmajor" class="layui-input-block">
                        <option value="Java" selected>Java</option>
                        <option value="HTML5">HTML5</option>
                    </select>
                </div>
              <input value="添加队员" type="button" class="layui-btn" style="display: inline-block;width: 20%" onclick="addStudent();">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="btn" class="layui-form-label">
            </label>
            <button id="btn" class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    function addStudent(){
        var realName=$("#realName").val();
        var phone=$("#phone").val();
        // var major=$(".layui-this")[1].innerText();
        var major=$("#checkmajor").val();
        var clazzid=getUrlParam("id");


        console.log(major)
        $.ajax({
            type:"post",
            url:"../../student/insertStudents",
            data:{"realName":realName,"phone":phone,"major":major,"clazzid":clazzid},
            success:function (res){
                if(res.status!=1){
                    alert("添加成功");
                    $("#realName").val("");
                    $("#phone").val("");
                }
            }
        })
    }
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return 1;
    }
// 填充带班老师
    $.ajax({
        type:"post",
        url:"../../teacher/queryAll",
        data: "",
        success: function (res) {
            var content=" <option value=\"\">请选择带队人员</option>";
            for (var i = 0; i < res.data.length; i++) {
                content+="<option value='"+res.data[i].uid+"'>"+res.data[i].realName+"</option>";
            }
            $("#per").html(content);
            console.log(content);
        }
    })

    // 填充班级信息
    $.ajax({
        type:"post",
        url:"/clazz/getById",
        data: "id="+getUrlParam("id"),
        success:function (res){
            $("#clazzname").text(res.data.clazzName);
            $("#start").text(res.data.start);
            $("#major").text(res.data.major);
        }
    })

    layui.use(['form', 'layer', 'laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        // var laydate = layui.laydate;
        // laydate.render({
        //     elem: '#start' //指定元素
        // });


        //监听提交
        form.on('submit(add)', function (data) {
            data.field.id = getUrlParam("id");
            console.log(data);
            //发异步，把数据提交给php
            $.ajax({
                type: "post",
                url: "../../clazz/updateById",
                data: data.field,
                success: function (res) {
                    if (res.status != 1) {
                        // console.log(res);
                        layer.alert("修改成功", {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }

                }
            })
            return false;
        });
    });
</script>
</body>

</html>